package com.ypinkj.app.api;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ypinkj.app.entity.CompanyInformationPerfection;
import com.ypinkj.app.mapper.CompanyInformationPerfectionMapper;
import com.ypinkj.app.utils.resultutils.Result;
import com.ypinkj.app.utils.resultutils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author LF
 * @since 2020-10-20
 */
@Api(tags = "企业信息完善")
@RestController
@RequestMapping("/company-information-perfection")
public class CompanyInformationPerfectionController {

    @Autowired
    CompanyInformationPerfectionMapper informationPerfectionMapper;

    @ApiOperation("保存修改")
    @PutMapping
    public Result save(@RequestBody CompanyInformationPerfection companyInformationPerfection){
        String id = companyInformationPerfection.getId();
        if (id==null){
            int i = informationPerfectionMapper.insert(companyInformationPerfection);
            return i>0 ? ResultUtil.success(companyInformationPerfection) : ResultUtil.errorMsg();
        }else {
            int i = informationPerfectionMapper.updateInfo(companyInformationPerfection);
            return i>0 ? ResultUtil.success() : ResultUtil.errorMsg();
        }
    }

    @ApiOperation("根据企业用户id获取信息")
    @GetMapping
    public Result getInfo(String companyId){
        LambdaQueryWrapper<CompanyInformationPerfection> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(CompanyInformationPerfection::getCompany_id,companyId);
        List<CompanyInformationPerfection> list = informationPerfectionMapper.selectList(wrapper);
        return list.size()>0 ? ResultUtil.success(list.get(0)) : ResultUtil.success(null);
    }
}
